package com.wlyuan.open.domain.source.assembler;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.core.marker.NamedStatus;
import com.wlyuan.open.domain.source.utils.MappingOrder;
import com.wlyuan.open.dto.OpenOrderSyncDTO;
import com.wlyuan.open.dto.order.OrderTransportDTO;
import com.wlyuan.order.dto.rewrite.OrderCreationSyncDTO;
import com.wlyuan.order.dto.rewrite.OrderMultiTransportDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author lijing
 * @description
 */
public class OrderAssembler {

    private static final Assembler ASSEMBLER = Mappers.getMapper(Assembler.class);

    @Mapper(uses = {
            MappingIds.class,
            MappingOrder.class,
    }, imports = {
            NamedStatus.class,
    })
    public interface Assembler {
        @Mappings({
                @Mapping(source = "info.orderNo", target = "orderNo"),
                @Mapping(source = "info.contractNo", target = "contractNo"),
                @Mapping(source = "info.customerId", target = "customerId"),
                @Mapping(source = "info.desc", target = "desc"),
                @Mapping(source = "info.trackType", target = "trackType"),
                @Mapping(source = "info.deviceCode", target = "deviceCode"),
                @Mapping(source = "info.weightAddition", target = "weightAddition"),
                @Mapping(source = "info.volumeAddition", target = "volumeAddition"),
                @Mapping(source = "info.valueAddition", target = "valueAddition"),
                @Mapping(source = "info.totalValue", target = "totalValue"),
                @Mapping(source = "info.days", target = "days"),
                @Mapping(source = "info.signAt", target = "signAt"),
                @Mapping(source = "info.receiptSignTime", target = "receiptSignTime"),
                @Mapping(source = "info.createMan", target = "createMan"),
                @Mapping(source = "info.createManDesc", target = "createManDesc"),
                @Mapping(source = "info.createOrderTime", target = "createOrderTime"),
                @Mapping(source = "info.signBy", target = "signBy"),
                @Mapping(source = "info.receiptAt", target = "receiptAt"),
                @Mapping(source = "info.receiptBy", target = "receiptBy"),
                @Mapping(source = "info.closeAt", target = "closeAt"),
                @Mapping(source = "info.closeBy", target = "closeBy"),
                @Mapping(source = "info.totalWeight", target = "totalWeight"),
                @Mapping(source = "info.totalVolume", target = "totalVolume"),
                @Mapping(source = "info.totalQuantity", target = "totalQuantity"),
                @Mapping(source = "info.totalCost", target = "totalCost"),
                @Mapping(source = "info.totalSignQuantity", target = "totalSignQuantity"),
                @Mapping(source = "info.totalSignExceptionQuantity", target = "totalSignExceptionQuantity"),
                @Mapping(source = "info.totalReceiptQuantity", target = "totalReceiptQuantity"),
                @Mapping(source = "info.totalReceiptExceptionQuantity", target = "totalReceiptExceptionQuantity"),
                @Mapping(source = "info.signType", target = "signType"),
                @Mapping(source = "info.signDesc", target = "signDesc"),
                @Mapping(source = "info.receiptDesc", target = "receiptDesc"),
                @Mapping(source = "info.closeDesc", target = "closeDesc"),
                @Mapping(source = "info.status", target = "status"),
                @Mapping(source = "info.exceptionStatus", target = "exceptionStatus"),
                @Mapping(source = "info.customerName", target = "customerName"),
                @Mapping(source = "info.customerType", target = "customerType"),
                @Mapping(source = "info.consigneeId", target = "consigneeId"),
                @Mapping(source = "info.consigneeName", target = "consigneeName"),
                @Mapping(source = "info.delayReason", target = "delayReason"),
                @Mapping(source = "sourceKey", target = "orderOldId"),

                @Mapping(source = "requirement.pick", target = "pick"),
                @Mapping(source = "requirement.onLoad", target = "onLoad"),
                @Mapping(source = "requirement.offLoad", target = "offLoad"),
                @Mapping(source = "requirement.insure", target = "insure"),
                @Mapping(source = "requirement.deliver", target = "deliver"),
                @Mapping(source = "requirement.shipMode", target = "shipMode"),
                @Mapping(source = "requirement.chargeMode", target = "chargeMode"),
                @Mapping(source = "requirement.transportMode", target = "transportMode"),
                @Mapping(source = "requirement.priceUnit", target = "priceUnit"),
                @Mapping(source = "requirement.goodsCategory", target = "goodsCategory"),
                @Mapping(source = "requirement.packageMode", target = "packageMode"),

                @Mapping(source = "vehicle.vehicleType", target = "vehicleMode.vehicleType"),
                @Mapping(source = "vehicle.vehicleLength", target = "vehicleMode.vehicleLength"),
                @Mapping(source = "vehicle.vehicleWeight", target = "vehicleMode.vehicleWeight"),
                @Mapping(source = "vehicle.vehicleVolume", target = "vehicleMode.vehicleVolume"),
                @Mapping(source = "vehicle.vehicleCount", target = "vehicleMode.vehicleCount"),

                @Mapping(source = "from.fromTime", target = "fromTime"),
                @Mapping(source = "from.contactName", target = "fromContact.contactName"),
                @Mapping(source = "from.contactMobile", target = "fromContact.contactMobile"),
                @Mapping(source = "from.provinceCode", target = "fromAddress.provinceCode"),
                @Mapping(source = "from.province", target = "fromAddress.province"),
                @Mapping(source = "from.cityCode", target = "fromAddress.cityCode"),
                @Mapping(source = "from.city", target = "fromAddress.city"),
                @Mapping(source = "from.districtCode", target = "fromAddress.districtCode"),
                @Mapping(source = "from.district", target = "fromAddress.district"),
                @Mapping(source = "from.address", target = "fromAddress.address"),
                @Mapping(source = "from.location", target = "fromAddress.location"),
                @Mapping(source = "from.locationType", target = "fromAddress.locationType"),

                @Mapping(source = "to.toTime", target = "toTime"),
                @Mapping(source = "to.contactName", target = "toContact.contactName"),
                @Mapping(source = "to.contactMobile", target = "toContact.contactMobile"),
                @Mapping(source = "to.provinceCode", target = "toAddress.provinceCode"),
                @Mapping(source = "to.province", target = "toAddress.province"),
                @Mapping(source = "to.cityCode", target = "toAddress.cityCode"),
                @Mapping(source = "to.city", target = "toAddress.city"),
                @Mapping(source = "to.districtCode", target = "toAddress.districtCode"),
                @Mapping(source = "to.district", target = "toAddress.district"),
                @Mapping(source = "to.address", target = "toAddress.address"),
                @Mapping(source = "to.location", target = "toAddress.location"),
                @Mapping(source = "to.locationType", target = "toAddress.locationType"),

                @Mapping(source = "orderReceiptDevice.orderId", target = "orderDeviceCache.orderId"),
                @Mapping(source = "orderReceiptDevice.tenantId", target = "orderDeviceCache.tenantId"),
                @Mapping(source = "orderReceiptDevice.generateCert", target = "orderDeviceCache.generateCert"),
                @Mapping(source = "orderReceiptDevice.score", target = "orderDeviceCache.score"),
                @Mapping(source = "orderReceiptDevice.scoreDesc", target = "orderDeviceCache.scoreDesc"),
                @Mapping(source = "orderReceiptDevice.arrive", target = "orderDeviceCache.arrive"),
                @Mapping(source = "orderReceiptDevice.realFromTime", target = "orderDeviceCache.realFromTime"),
                @Mapping(source = "orderReceiptDevice.realToTime", target = "orderDeviceCache.realToTime"),
                @Mapping(source = "orderReceiptDevice.smsFromTime", target = "orderDeviceCache.smsFromTime"),
                @Mapping(source = "orderReceiptDevice.smsToTime", target = "orderDeviceCache.smsToTime"),
                @Mapping(source = "orderReceiptDevice.deviceBindTime", target = "orderDeviceCache.deviceBindTime"),
                @Mapping(source = "orderReceiptDevice.estimateArriveTime", target = "orderDeviceCache.estimateArriveTime"),

        })
        OrderCreationSyncDTO assembler(OpenOrderSyncDTO source);

        @Mappings({
                @Mapping(source = "type", target = "transportType"),
                @Mapping(source = "remark", target = "remarks"),
                @Mapping(source = "arrive", target = "arriveFlag"),
        })
        OrderMultiTransportDTO assembler(OrderTransportDTO source);

    }

    public static OrderCreationSyncDTO assembler(OpenOrderSyncDTO source) {
        return ASSEMBLER.assembler(source);
    }
}
